<?php

class HTech_Model_Resource extends Zend_Db_Table_Abstract
{
    
    public function getResources($roleId = null)
    {
        $db = $this->getAdapter();
        $sql = $db->quoteInto("
            select
                concat(r.Module,'.',r.Controller,'.',r.Action) resource, 
                r.ResourceId
            from
                resources r
            left join
                lnk_resources_roles rr on rr.RoleId = ? and rr.ResourceId = r.ResourceId 
            where
                r.Public = 'Yes' or r.ResourceId = rr.ResourceId", self::_getRoleId($roleId));
        return $db->fetchPairs($sql);
    }

    protected function _getRoleId($roleId = null)
    {
        return $roleId ? $roleId : Zend_Auth::getInstance()->getIdentity()->RoleId;
    }

}
